﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dangnhap.aspx.cs" Inherits="QLBH.UI.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Đăng nhập</title>
    <link href="slidebars/scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="slidebars/scripts/bootstrap/css/signin.css" rel="stylesheet" />
    <style type="text/css">
        .checkbox {
            margin-left: 20px;
        }

        h2 {
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">

        <form class="form-signin" role="form" id="form_dang_nhap" runat="server">
            <h2 class="form-signin-heading">Đăng nhập</h2>
            <input id="txt_ten_dn" type="text" class="form-control" placeholder="Tên đăng nhập" required autofocus />
            <input id="txt_mat_khau" type="password" class="form-control" placeholder="Mật khẩu" required />
            <label class="checkbox">
                <input type="checkbox" value="remember-me" />
                Ghi nhớ
       
            </label>
            <span id="btn_dang_nhap" class="btn btn-lg btn-primary btn-block">Đăng nhập</span>
        </form>

    </div>
    <script src="slidebars/scripts/bootstrap/js/jquery.min.js"></script>
    <script src="slidebars/scripts/bootstrap/js/jquery.blockUI.js"></script>
    <script src="slidebars/scripts/bootstrap/js/run_prettify.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {

            function BlockUI() {
                $.blockUI({
                    message: "<img src='images/ajax-loader.gif'/>", css: { left: '50%', cursor: 'wait', backgroundColor: 'none', border: 'none', width: '50px' },
                    overlayCSS: { backgroundColor: 'none', opacity: 0.0, cursor: 'wait' }
                });
            }

            function Kiemtrahople() {
                if ($('#txt_ten_dn').val().length <= 0) {
                    $('#txt_ten_dn').focus();
                    $('#txt_ten_dn').tooltip({ placement: 'top', title: 'Bạn cần nhập tên đăng nhập' });
                    return false;
                }

                if ($('#txt_mat_khau').val().length <= 0) {
                    $('#txt_mat_khau').focus();
                    $('#txt_mat_khau').tooltip({ placement: 'top', title: 'Bạn cần nhập mật khẩu' });
                    return false;
                }

                return true;
            }

            function SetSession(key, values) {
                var DTO = {
                    'key': key,
                    'values': values
                };
                $.ajax({
                    type: "POST",
                    url: "DangNhap.aspx/SetSessionValue",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        window.location.replace("Default.aspx");
                    },
                    error: function (data) {
                        alert(data.d);
                    }

                });
            }



            $("#btn_dang_nhap").click(function (e) {
                e.preventDefault();
                if (!Kiemtrahople()) {
                    return false;
                }
                BlockUI();
                var DTO = {
                    'ten_dang_nhap': $("#txt_ten_dn").val(),
                    'mat_khau': $("#txt_mat_khau").val()
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/DangNhap",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1)
                            alert(obj.ERROR);
                        else {
                            var TEN_DANG_NHAP = obj.TEN_DANG_NHAP;
                            var MA_NHAN_VIEN = obj.MA_NHAN_VIEN;
                            SetSession('TEN_DANG_NHAP', TEN_DANG_NHAP);

                          //  '<%Session["TEN_DANG_NHAP"] = "' + TEN_DANG_NHAP + '"; %>';
                          //  '<%Session["MA_NHAN_VIEN"] = "' + MA_NHAN_VIEN + '"; %>';
                          //  window.location.replace("Default.aspx");
                        }
                    },
                    error: function (data) {
                        alert(data.d);
                    }

                });
            });

        });
    </script>
</body>
</html>
